package com.klz.iblog.controller.test;

import com.klz.iblog.common.Result;
import com.klz.iblog.common.ResultGenerator;
import com.klz.iblog.pojo.Admin;
import com.klz.iblog.service.AdminService;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class AdminController {

    @Autowired
    private AdminService adminService;

    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "int" , paramType = "query")
    @RequestMapping("/info")
    public Result<Admin> admin(@RequestParam("userId") Integer userId) {
        if(userId == null || userId < 1) {
            return ResultGenerator.genFailResult("参数异常");
        }
        if(adminService.selectByPrimaryKey(userId) == null) {
            return ResultGenerator.genFailResult("无此数据");
        }
        return ResultGenerator.genSuccessResult(adminService.selectByPrimaryKey(userId));
    }
}
